package com.java110.mall.goods.bmo.housekeepingResource.impl;

import com.java110.mall.goods.bmo.housekeepingResource.IGetHousekeepingResourceBMO;
import com.java110.intf.goods.IHousekeepingResourceInnerServiceSMO;
import com.java110.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import com.java110.dto.housekeeping.HousekeepingResourceDto;

import java.util.ArrayList;
import java.util.List;

@Service("getHousekeepingResourceBMOImpl")
public class GetHousekeepingResourceBMOImpl implements IGetHousekeepingResourceBMO {

    @Autowired
    private IHousekeepingResourceInnerServiceSMO housekeepingResourceInnerServiceSMOImpl;

    /**
     *
     *
     * @param  housekeepingResourceDto
     * @return 订单服务能够接受的报文
     */
    public ResponseEntity<String> get(HousekeepingResourceDto housekeepingResourceDto) {


        int count = housekeepingResourceInnerServiceSMOImpl.queryHousekeepingResourcesCount(housekeepingResourceDto);

        List<HousekeepingResourceDto> housekeepingResourceDtos = null;
        if (count > 0) {
            housekeepingResourceDtos = housekeepingResourceInnerServiceSMOImpl.queryHousekeepingResources(housekeepingResourceDto);
        } else {
            housekeepingResourceDtos = new ArrayList<>();
        }

        ResultVo resultVo = new ResultVo((int) Math.ceil((double) count / (double) housekeepingResourceDto.getRow()), count, housekeepingResourceDtos);

        ResponseEntity<String> responseEntity = new ResponseEntity<String>(resultVo.toString(), HttpStatus.OK);

        return responseEntity;
    }

}
